home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / CenterScreen.as < prev    next >
Encoding:
Text File  |  2013-04-24  |  9.6 KB  |  321 lines

  1. class CenterScreen extends State
  2. {
  3.    var oCurrentMinigame;
  4.    var oCurrentAlgae;
  5.    var oCurrentJelly;
  6.    var oCurrentWall;
  7.    var oInterface;
  8.    var mcRef;
  9.    var oTransition;
  10.    var sNextState;
  11.    var sState;
  12.    static var sSTATE_IDLE = "Idle";
  13.    static var sSTATE_TURNLEFT = "TurnLeft";
  14.    static var sSTATE_TURNRIGHT = "TurnRight";
  15.    static var sSTATE_MOVEFORWARD = "MoveForward";
  16.    static var sSTATE_TURN180_LEFT = "Turn180Left";
  17.    static var sSTATE_TURN180_RIGHT = "Turn180Right";
  18.    static var sSTATE_TURN180_UP = "Turn180Up";
  19.    static var sSTATE_TURN180_DOWN = "Turn180Down";
  20.    static var sSTATE_MG_BREAKWALL = "MG_BreakTheWall";
  21.    static var sSTATE_MG_JELLYFISHSWARM = "MG_JellyFishSwarm";
  22.    static var sSTATE_MG_PUSHBUS = "MG_PushTheBus";
  23.    function CenterScreen(_mcRef)
  24.    {
  25.       super(_mcRef);
  26.       this.oCurrentMinigame = null;
  27.       this.oCurrentAlgae = null;
  28.       this.oCurrentJelly = null;
  29.       this.oCurrentWall = null;
  30.       this.oInterface = new Interface(this.mcRef.mcInterface);
  31.       this.oTransition = new MinigameTransition(this.mcRef.mcTransition);
  32.       this.sNextState = "";
  33.       this.setState(CenterScreen.sSTATE_IDLE);
  34.    }
  35.    function cleanUp()
  36.    {
  37.       super.cleanUp();
  38.       if(this.oCurrentMinigame != null)
  39.       {
  40.          this.oCurrentMinigame.destroyMiniGame(true);
  41.          delete this.oCurrentMinigame;
  42.          this.oCurrentMinigame = null;
  43.       }
  44.       if(this.oCurrentAlgae != null)
  45.       {
  46.          this.oCurrentAlgae.cleanUp();
  47.          delete this.oCurrentAlgae;
  48.       }
  49.       if(this.oCurrentJelly != null)
  50.       {
  51.          this.oCurrentJelly.cleanUp();
  52.          delete this.oCurrentJelly;
  53.       }
  54.       if(this.oCurrentWall != null)
  55.       {
  56.          this.oCurrentWall.cleanUp();
  57.          delete this.oCurrentWall;
  58.       }
  59.    }
  60.    function startBreakTheWall(_oWall)
  61.    {
  62.       if(!this.isInMiniGame())
  63.       {
  64.          this.oCurrentWall = _oWall;
  65.          this.goTo(CenterScreen.sSTATE_MG_BREAKWALL);
  66.          this.setState(CenterScreen.sSTATE_IDLE);
  67.          CTRLGame.getRef().Screen.getInterface().pauseTime();
  68.          CTRLGame.getRef().stopAnimElements();
  69.       }
  70.    }
  71.    function startJellyFishSwarm(_oJelly)
  72.    {
  73.       if(!this.isInMiniGame())
  74.       {
  75.          this.oCurrentJelly = _oJelly;
  76.          this.goTo(CenterScreen.sSTATE_MG_JELLYFISHSWARM);
  77.          this.setState(CenterScreen.sSTATE_IDLE);
  78.          CTRLGame.getRef().Screen.getInterface().pauseTime();
  79.          CTRLGame.getRef().stopAnimElements();
  80.       }
  81.    }
  82.    function startPushTheBus(_oAlgae)
  83.    {
  84.       if(!this.isInMiniGame())
  85.       {
  86.          this.oCurrentAlgae = _oAlgae;
  87.          this.goTo(CenterScreen.sSTATE_MG_PUSHBUS);
  88.          this.setState(CenterScreen.sSTATE_IDLE);
  89.          CTRLGame.getRef().Screen.getInterface().pauseTime();
  90.          CTRLGame.getRef().stopAnimElements();
  91.       }
  92.    }
  93.    function isInMiniGame()
  94.    {
  95.       var _loc2_ = false;
  96.       if(this.sState == CenterScreen.sSTATE_MG_BREAKWALL || (this.sState == CenterScreen.sSTATE_MG_JELLYFISHSWARM || (this.sState == CenterScreen.sSTATE_MG_PUSHBUS || !this.oTransition.isInIdle())))
  97.       {
  98.          _loc2_ = true;
  99.       }
  100.       return _loc2_;
  101.    }
  102.    function manageAnim(_nNewDir, _nLastDir, _nMovement)
  103.    {
  104.       if(_nMovement == 0)
  105.       {
  106.          if(this.isSkippableState())
  107.          {
  108.             this.setState(CenterScreen.sSTATE_IDLE);
  109.          }
  110.          else
  111.          {
  112.             this.sNextState = CenterScreen.sSTATE_IDLE;
  113.          }
  114.       }
  115.       else if(_nNewDir == CTRLGame.nDIR_DOWN && _nLastDir == CTRLGame.nDIR_DOWN || (_nNewDir == CTRLGame.nDIR_UP && _nLastDir == CTRLGame.nDIR_UP || (_nNewDir == CTRLGame.nDIR_LEFT && _nLastDir == CTRLGame.nDIR_LEFT || _nNewDir == CTRLGame.nDIR_RIGHT && _nLastDir == CTRLGame.nDIR_RIGHT)))
  116.       {
  117.          if(this.isSkippableState())
  118.          {
  119.             this.setState(CenterScreen.sSTATE_MOVEFORWARD);
  120.          }
  121.          else
  122.          {
  123.             this.sNextState = CenterScreen.sSTATE_MOVEFORWARD;
  124.          }
  125.       }
  126.       else if(_nNewDir == CTRLGame.nDIR_DOWN && _nLastDir == CTRLGame.nDIR_UP)
  127.       {
  128.          if(this.isSkippableState())
  129.          {
  130.             this.setState(CenterScreen.sSTATE_TURN180_DOWN);
  131.          }
  132.          else
  133.          {
  134.             this.sNextState = CenterScreen.sSTATE_TURN180_DOWN;
  135.          }
  136.       }
  137.       else if(_nNewDir == CTRLGame.nDIR_RIGHT && _nLastDir == CTRLGame.nDIR_LEFT)
  138.       {
  139.          if(this.isSkippableState())
  140.          {
  141.             this.setState(CenterScreen.sSTATE_TURN180_LEFT);
  142.          }
  143.          else
  144.          {
  145.             this.sNextState = CenterScreen.sSTATE_TURN180_LEFT;
  146.          }
  147.       }
  148.       else if(_nNewDir == CTRLGame.nDIR_LEFT && _nLastDir == CTRLGame.nDIR_RIGHT)
  149.       {
  150.          if(this.isSkippableState())
  151.          {
  152.             this.setState(CenterScreen.sSTATE_TURN180_RIGHT);
  153.          }
  154.          else
  155.          {
  156.             this.sNextState = CenterScreen.sSTATE_TURN180_RIGHT;
  157.          }
  158.       }
  159.       else if(_nNewDir == CTRLGame.nDIR_UP && _nLastDir == CTRLGame.nDIR_DOWN)
  160.       {
  161.          if(this.isSkippableState())
  162.          {
  163.             this.setState(CenterScreen.sSTATE_TURN180_UP);
  164.          }
  165.          else
  166.          {
  167.             this.sNextState = CenterScreen.sSTATE_TURN180_UP;
  168.          }
  169.       }
  170.       else if(_nNewDir == CTRLGame.nDIR_DOWN && _nLastDir == CTRLGame.nDIR_LEFT || (_nNewDir == CTRLGame.nDIR_LEFT && _nLastDir == CTRLGame.nDIR_UP || (_nNewDir == CTRLGame.nDIR_UP && _nLastDir == CTRLGame.nDIR_RIGHT || _nNewDir == CTRLGame.nDIR_RIGHT && _nLastDir == CTRLGame.nDIR_DOWN)))
  171.       {
  172.          if(this.isSkippableState())
  173.          {
  174.             this.setState(CenterScreen.sSTATE_TURNLEFT);
  175.          }
  176.          else
  177.          {
  178.             this.sNextState = CenterScreen.sSTATE_TURNLEFT;
  179.          }
  180.       }
  181.       else if(_nNewDir == CTRLGame.nDIR_DOWN && _nLastDir == CTRLGame.nDIR_RIGHT || (_nNewDir == CTRLGame.nDIR_RIGHT && _nLastDir == CTRLGame.nDIR_UP || (_nNewDir == CTRLGame.nDIR_UP && _nLastDir == CTRLGame.nDIR_LEFT || _nNewDir == CTRLGame.nDIR_LEFT && _nLastDir == CTRLGame.nDIR_DOWN)))
  182.       {
  183.          if(this.isSkippableState())
  184.          {
  185.             this.setState(CenterScreen.sSTATE_TURNRIGHT);
  186.          }
  187.          else
  188.          {
  189.             this.sNextState = CenterScreen.sSTATE_TURNRIGHT;
  190.          }
  191.       }
  192.    }
  193.    function setState(_sState)
  194.    {
  195.       var _loc4_ = this.sState;
  196.       super.setState(_sState);
  197.       if(this.sState == CenterScreen.sSTATE_MG_BREAKWALL)
  198.       {
  199.          this.oCurrentMinigame = new MiniGames.BTW.BreakTheWallMG(this.mcRef.mcState);
  200.       }
  201.       else if(this.sState == CenterScreen.sSTATE_MG_JELLYFISHSWARM)
  202.       {
  203.          this.oCurrentMinigame = new MiniGames.JFS.JellyFishSwarmMG(this.mcRef.mcState);
  204.       }
  205.       else if(this.sState == CenterScreen.sSTATE_MG_PUSHBUS)
  206.       {
  207.          this.oCurrentMinigame = new MiniGames.PTB.PushTheBusMG(this.mcRef.mcState);
  208.       }
  209.       if(_loc4_ == CenterScreen.sSTATE_MG_BREAKWALL || (_loc4_ == CenterScreen.sSTATE_MG_JELLYFISHSWARM || _loc4_ == CenterScreen.sSTATE_MG_PUSHBUS))
  210.       {
  211.          if(this.sState == CenterScreen.sSTATE_IDLE)
  212.          {
  213.             CTRLGame.getRef().Screen.getInterface().unPauseTime();
  214.             CTRLGame.getRef().resumeAnimElements();
  215.          }
  216.       }
  217.    }
  218.    function getInterface()
  219.    {
  220.       return this.oInterface;
  221.    }
  222.    function isSkippableState()
  223.    {
  224.       var _loc2_ = false;
  225.       if(this.sState == CenterScreen.sSTATE_MOVEFORWARD || this.sState == CenterScreen.sSTATE_IDLE)
  226.       {
  227.          _loc2_ = true;
  228.       }
  229.       return _loc2_;
  230.    }
  231.    function manageEndMiniGame()
  232.    {
  233.       if(this.oCurrentMinigame.isFinished() && this.oCurrentMinigame != null)
  234.       {
  235.          this.oCurrentMinigame.destroyMiniGame();
  236.          delete this.oCurrentMinigame;
  237.          this.oCurrentMinigame = null;
  238.          if(this.sState == CenterScreen.sSTATE_MG_BREAKWALL)
  239.          {
  240.             this.oCurrentWall.cleanUp();
  241.             delete this.oCurrentWall;
  242.             this.oCurrentWall = null;
  243.          }
  244.          else if(this.sState == CenterScreen.sSTATE_MG_JELLYFISHSWARM)
  245.          {
  246.             this.oCurrentJelly.cleanUp();
  247.             delete this.oCurrentJelly;
  248.             this.oCurrentJelly = null;
  249.          }
  250.          else
  251.          {
  252.             this.oCurrentAlgae.cleanUp();
  253.             delete this.oCurrentAlgae;
  254.             this.oCurrentAlgae = null;
  255.          }
  256.          this.goTo(CenterScreen.sSTATE_IDLE);
  257.       }
  258.    }
  259.    function manageTempState()
  260.    {
  261.       if(this.stateFinished())
  262.       {
  263.          if(this.sNextState != "")
  264.          {
  265.             this.setState(this.sNextState);
  266.             this.sNextState = "";
  267.          }
  268.          else
  269.          {
  270.             this.setState(CenterScreen.sSTATE_MOVEFORWARD);
  271.          }
  272.       }
  273.    }
  274.    function goTo(_sState)
  275.    {
  276.       this.oTransition.goTo(_sState);
  277.    }
  278.    function Idle()
  279.    {
  280.    }
  281.    function MoveForward()
  282.    {
  283.    }
  284.    function TurnLeft()
  285.    {
  286.       this.manageTempState();
  287.    }
  288.    function TurnRight()
  289.    {
  290.       this.manageTempState();
  291.    }
  292.    function Turn180Left()
  293.    {
  294.       this.manageTempState();
  295.    }
  296.    function Turn180Right()
  297.    {
  298.       this.manageTempState();
  299.    }
  300.    function Turn180Up()
  301.    {
  302.       this.manageTempState();
  303.    }
  304.    function Turn180Down()
  305.    {
  306.       this.manageTempState();
  307.    }
  308.    function MG_BreakTheWall()
  309.    {
  310.       this.manageEndMiniGame();
  311.    }
  312.    function MG_JellyFishSwarm()
  313.    {
  314.       this.manageEndMiniGame();
  315.    }
  316.    function MG_PushTheBus()
  317.    {
  318.       this.manageEndMiniGame();
  319.    }
  320. }
  321.